<template>
	<view class="container">
		<uni-forms ref="flowForm" :modelValue="formData" class="form" label-width="120px">
			<uni-forms-item label="工单类别">
				<view class="uni-input">{{info.flow.typeName}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请部门" >
				<view class="uni-input">{{info.flow.deptName}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请人" >
				<view class="uni-input">{{info.flow.userName}}</view>
			</uni-forms-item>
			<uni-forms-item label="资产分类" >
				<view class="uni-input">{{info.flow.cateName}}</view>
			</uni-forms-item>
			<uni-forms-item label="采购数量" v-if="info.typeCode == 'purchase'">
				<view class="uni-input">{{info.flow.amount}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请资产" v-if="info.typeCode != 'purchase'">
				<view class="uni-input">{{info.flow.assetNum}}</view>
			</uni-forms-item>
			<uni-forms-item label="单价">
				<view class="uni-input">{{info.flow.price}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请原因">
				<view class="uni-input">{{info.flow.reason}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请说明">
				<view class="uni-input">{{info.flow.content}}</view>
			</uni-forms-item>
			<uni-forms-item label="申请申请">
				<view class="uni-input">{{info.flow.applyTime}}</view>
			</uni-forms-item>
			<template v-if="action == 'view'">
				<uni-forms-item label="审核状态">
					<view class="uni-input">{{dictTag('flow_check_status', info.checkStatus)}}</view>
				</uni-forms-item>
				<uni-forms-item label="工单状态">
					<view class="uni-input">{{dictTag('asset_flow_status', info.flowStatus)}}</view>
				</uni-forms-item>				
			</template>
			<template v-else>
			<uni-forms-item label="审核结果" required>
				<view class="uni-padding-wrap">
					<view>
					<radio-group @change="checkChange">
						<template v-for="(o,i) in dictOptions['flow_check_status']">							
							<label class="radio" v-if="o.dictValue != '0'">
								<radio :value="o.dictValue" :checked="formData.checkStatus == o.dictValue" />
							{{o.dictLabel}}</label>
						</template>
					</radio-group>
					</view>
				</view>
			</uni-forms-item>
			<uni-forms-item label="审核说明" required>
				<uni-easyinput type="textarea" v-model="formData.checkComment" placeholder="请输入您的审核意见" />
			</uni-forms-item>
			</template>
		</uni-forms>
		<button type="primary" v-if="action == 'check'" @click="submit">提交审核</button>	
	</view>
</template>


<script>
	import { getFlowCheck, checkFlow } from '@/api/flow.js'
	import { dictMixin } from '@/plugins/dict.js';
	export default {
		mixins: [dictMixin],
		data() {
			return {
				// 表单数据
				info: {flow:{}},
				formData:{
					id: null,
					flowId:null,
					stepId: null,
					checkStatus: null,
					checkComment: null,
				},
				action: 'view',
				checkOptions:[],
			}
		},
		onLoad() {				
			this.useDict(['flow_check_status', 'asset_flow_status']);				
			
			if(this.$route.query.action){
				this.action = this.$route.query.action;
			}		
			
			getFlowCheck(this.$route.query.id).then(response => {
				this.info = response.data;	
				if(this.action == 'check'){
					this.formData.id = this.info.id;
					this.formData.flowId = this.info.flowId;
					this.formData.stepId = this.info.stepId;
				}
			})		
		},
		methods: {
			submit(ref) {
				if(!this.formData.checkStatus){
					this.$modal.msgError('请选择审核结果');
					return;
				}
				checkFlow(this.formData).then(response => {
					this.$modal.showToast('审核成功');
					this.$tab.navigateBack();						
				});
			},
			checkChange(e){
				this.formData.checkStatus = e.detail.value;
			}
		}
	}
</script>

<style>
	.form {
		padding: 15px;
		background-color: #fff;
	}
	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
</style>